<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="请输入用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
const axios = require("axios");
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    onSubmit(values) {
      var _that = this;

      axios
        .get(
          "/api/vue_denglu?username=" + _that.username + "&&password=" + _that.password
        )
        .then(function (res) {
          console.log(res.data);
          console.log('id为',res.data.id.id);
          if (res.data.code > 0) {
              localStorage.setItem('username',_that.username)
              localStorage.setItem('id',res.data.id.id)
              localStorage.setItem('fen',res.data.fen.fen)
              localStorage.setItem('fenSum',res.data.fenSum.fenSum)
            _that.$router.push("/home");
          }
          if (res.data.code < 0) {
              alert('账号和密码不正确')
            _that.username=''
            _that.password=''
          }
        })
        .catch(function (err) {
          console.log(err.data);
        });
    },
  },
};
</script>

<style scoped>
</style>